import request from '@/config/axios'

// 新增：加班时长计算
export interface OvertimeDurationCalcReqVO {
  overtimeType: number
  startTime: string
  endTime: string
}
export interface OvertimeDurationCalcRespVO {
  duration: number
  unit: string
  rawHours: number
  days?: number
}

// OA 加班申请 VO
export interface OvertimeApplyVO {
  id: number // 序号
  overtimeType: number // 加班类型：1工作日加班 2休息日加班 3节假日加班
  startTime: string // 开始时间
  endTime: string // 结束时间
  compensateType: number // 补偿方式：1调休 2加班费
  reason: string // 加班原因
  processInstanceId: string // 流程实例的编号
}

// OA 加班申请 API
export const OvertimeApplyApi = {
  // 查询OA 加班申请分页
  getOvertimeApplyPage: async (params: any) => {
    return await request.get({ url: `/oa/overtime-apply/page`, params })
  },

  // 查询OA 加班申请详情
  getOvertimeApply: async (id: number) => {
    return await request.get({ url: `/oa/overtime-apply/get?id=` + id })
  },

  // 新增OA 加班申请
  createOvertimeApply: async (data: OvertimeApplyVO) => {
    return await request.post({ url: `/oa/overtime-apply/create`, data })
  },

  // 修改OA 加班申请
  updateOvertimeApply: async (data: OvertimeApplyVO) => {
    return await request.put({ url: `/oa/overtime-apply/update`, data })
  },

  // 删除OA 加班申请
  deleteOvertimeApply: async (id: number) => {
    return await request.delete({ url: `/oa/overtime-apply/delete?id=` + id })
  },

  // 导出OA 加班申请 Excel
  exportOvertimeApply: async (params) => {
    return await request.download({ url: `/oa/overtime-apply/export-excel`, params })
  },

  // 新增：加班时长计算
  calcOvertimeDuration: async (data: OvertimeDurationCalcReqVO): Promise<OvertimeDurationCalcRespVO> => {
    return await request.post({ url: '/oa/overtime-apply/calc-duration', data })
  },

  // 统计指定用户本年度每月审核通过的加班申请数量
  getMonthlyApprovedCountByUser: async (userId: number, year: number) => {
    return await request.get({ url: `/oa/overtime-apply/monthly-statistics`, params: { userId, year } })
  }
}
